<?php

    class Nalog_m extends Model {

        function Nalog_m () {
            parent::Model();
            $this->load->library('form_validation');            
        }

        function provjeri_podatke_naloga() {
            if(isset($_GET['jsoncall'])) {
                $_POST = $_GET;
            }
            if($this->provjera()) {                
                /*EMAIL EXIST IN DB?*/
                $numrow = $this->db->where('email',$this->input->get('email'))->get('account')->num_rows();
                $this->firephp->fb('Email: postoji u bazi');                      
                if($numrow == 1) {
                    $this->firephp->fb('Email: postoji u bazi');                      
                    return array('success'=>'failed','message'=>'Korisnik sa E-mailom vec postoji u bazi!');                    
                }

                return array('success'=>'success');
            }else {
                $html = preg_replace(
                array('/\n/','/\r/','/\t/'),
                array(''),
                $this->errors);  
                return array('success'=>'failed','message'=>$html);
            }
        }

        function provjera() {
            $this->form_validation->set_rules('firstname','<b>Ime</b>','trim|required');
            $this->form_validation->set_rules('lastname','<b>Prezime</b>','trim|required');
            $this->form_validation->set_rules('city','<b>Grad</b>','trim|required');                                          
            $this->form_validation->set_rules('zip','<b>Postanski proj</b>','trim|required');                                          
            $this->form_validation->set_rules('address1','<b>Adresa</b>','trim|required'); 
            $this->form_validation->set_rules('email','<b>Email</b>','trim|required|valid_email');
            $this->form_validation->set_rules('country_ccode','Molimo odaverite državu.','registrationCountry');
            $this->form_validation->set_rules('password_one','<b>Password</b>','required|min_length[5]|max_length[12]');
            $this->form_validation->set_rules('password_conf','<b>Re-Password</b>','required|matches[password_one]');

            $this->form_validation->set_message('registrationCountry', 'Molimo odaverite državu.');
            
            if($this->form_validation->run()) { 
                return TRUE;
            }else {
                $this->errors = validation_errors(' ','<br />'); 
                return FALSE;
            }
        }        

        function listaj_drzave(){
            return $this->db->order_by("name", "asc")->get('country')->result();
        }

        function listaj_naloge(){
            return $this->db->get('account')->result();
        }

        function listaj_nalog($id){
            return $this->db->get_where('account', array('id'=> $id))->result();                                                               
        }
    }
?>